package main

import (
	"github.com/gin-gonic/gin"
	"log"
)

func main() {
	r := gin.Default()
	r.GET("/setCookie", func(c *gin.Context) {
		//设置cookie
		c.SetCookie("my_cookie", "value123", 3600, "/", "localhost", false, true)
		c.String(200, "cookie set success!")
	})

	r.GET("/getCookie", func(c *gin.Context) {
		//读取cookie
		cookie, err := c.Cookie("my_cookie")
		if err != nil {
			log.Println(err)
			c.String(200, "not found cookie!")
		}
		c.String(200, cookie)

	})

	r.GET("/delCookie", func(c *gin.Context) {
		//将cookie maxAge设为-1表示删除cookie
		c.SetCookie("my_cookie", "", -1, "/", "localhost", false, true)
		c.String(200, "cookie delete success!")
	})

	r.Run(":8084")
}
